package com.df.bpm.controller;

import cn.dev33.satoken.annotation.SaCheckLogin;
import cn.dev33.satoken.annotation.SaIgnore;
import com.df.bpm.entity.Department;
import com.df.bpm.service.impl.DepartmentServiceImpl;
import com.df.common.entity.Pagination;
import com.df.common.utils.CommonUtils;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;


/**
 * 角色控制器
 */
@Slf4j
@Tag(name = "部门控制器")
@RequestMapping("/department")
@RequiredArgsConstructor
@RestController
@SaCheckLogin
public class DepartmentController {
    private final DepartmentServiceImpl departmentServiceImpl;

    /**
     * 查询部门
     * @param pagination 分页信息
     * @param temp 部门线索
     * @return  部门列表
     */
    @Operation(summary = "查询部门", description = "查询部门")
    @GetMapping("")
    @SaIgnore
    public ResponseEntity<?> getDtoRequirement(Pagination pagination, Department temp) {
        if (CommonUtils.varIsNotBlank(pagination.getPageNum(), pagination.getPageSize())) {
            PageHelper.startPage(pagination.getPageNum(), pagination.getPageSize());
            return ResponseEntity.ok(new PageInfo<>(departmentServiceImpl.getList4Like(temp)));
        } else {
            return ResponseEntity.ok(departmentServiceImpl.getList4Like(temp));
        }
    }

    /**
     * 新增部门
     * @param temp   部门信息
     * @return  新增成功后的部门信息
     */
    @Operation(summary = "新增部门", description = "新增部门")
    @PostMapping("")
    @SaIgnore
    public ResponseEntity<?> newRole(@RequestBody Department temp) {
        departmentServiceImpl.add(temp);
        return ResponseEntity.ok(temp);
    }

}
